<?php

/**
 * This is the model class for table "admins".
 *
 * The followings are the available columns in table 'admins':
 * @property integer $id
 * @property string $username
 * @property string $email
 * @property string $password
 * @property integer $gender
 * @property integer $permission_id
 * @property string $current_sign_at
 * @property string $last_visit
 * @property string $address
 * @property string $first_name
 * @property string $last_name
 * @property integer $status
 * @property string $created_at
 *
 * The followings are the available model relations:
 * @property Permissions $permission
 * @property Events[] $events
 * @property Events[] $events1
 */
class Admin extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Admin the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'admins';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('gender, permission_id, status', 'numerical', 'integerOnly'=>true),
			array('username, email, address, first_name, last_name', 'length', 'max'=>255),
			array('password, current_sign_at, last_visit, created_at', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, username, email, password, gender, permission_id, current_sign_at, last_visit, address, first_name, last_name, status, created_at', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'permission' => array(self::BELONGS_TO, 'Permissions', 'permission_id'),
			'events' => array(self::HAS_MANY, 'Events', 'updated_by'),
			'events1' => array(self::HAS_MANY, 'Events', 'created_by'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'username' => 'Username',
			'email' => 'Email',
			'password' => 'Password',
			'gender' => 'Gender',
			'permission_id' => 'Permission',
			'current_sign_at' => 'Current Sign At',
			'last_visit' => 'Last Visit',
			'address' => 'Address',
			'first_name' => 'First Name',
			'last_name' => 'Last Name',
			'status' => 'Status',
			'created_at' => 'Created At',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('gender',$this->gender);
		$criteria->compare('permission_id',$this->permission_id);
		$criteria->compare('current_sign_at',$this->current_sign_at,true);
		$criteria->compare('last_visit',$this->last_visit,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('created_at',$this->created_at,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}